import { getMoreApi, getTab1Api, getTab2Api } from "../../utils/api";
const indexModule = {
  state: {
    tab1list: [], // 最受好评
    tab2list: [],//首页电影列表
    ids: [],
    moreList: '',//上拉加载更多
  },
  mutations: {
    // 最受好评
    getTab1Data(state, payload) {
      state.tab1list = payload.result;
    },
    // 
    getTab2Data(state, payload) {
      state.tab2list = payload.result;
      state.ids = payload.ids;
      state.moreList = state.ids
        .slice(state.tab2list.length, state.tab2list.length + 6)
        .toString();
    },
    getmore(state, payload) {
      state.tab2list.splice(state.tab2list.length, 0, ...payload.result);
      state.moreList = state.ids
        .slice(state.tab2list.length, state.tab2list.length + 6)
        .toString();
    },
  },
  actions: {
    getTab1DataAsc({ commit }) {
      return new Promise((resolve) => {
        getTab1Api().then((res) => {
          commit("getTab1Data", res);
          resolve();
        });
      });
    },
    // 下拉电影
    getTab2DataAsc({ commit }) {
      return new Promise((resolve) => {
        getTab2Api().then((res) => {
          commit("getTab2Data", res);
          resolve();
        });
      })
    },
    // 获取更多
    getmoreAsc({ commit }, payload) {
      return new Promise((resolve) => {
        getMoreApi({ ids: payload }).then((res) => {
          commit("getmore", res);
          resolve();
        });
      });
    },
  }
}
export default indexModule;